void Insert( int index, T value )

robot_2Generated
code_blocksInput

Description

The Insert method allows you to insert an element of type T at a specified index within the NetList<T>. This method is sealed, meaning it cannot be overridden in derived classes. It is useful for adding elements at specific positions in the list, which can be important for maintaining order or priority.

Usage

To use the Insert method, specify the zero-based index where you want to insert the value. The method will shift any existing elements at or beyond the specified index to the right, increasing their indices by one.

Ensure that the index is within the bounds of the list (i.e., greater than or equal to 0 and less than or equal to the current count of elements in the list). If the index is out of range, an ArgumentOutOfRangeException will be thrown.

Example

// Example of using the Insert method in a NetList<T>
public class MyComponent : Component
{
    [Sync] public NetList<int> MyIntegerList { get; set; } = new();

    public void InsertNumberAt(int index, int number)
    {
        if (IsProxy) return;
        
        // Insert the number at the specified index
        MyIntegerList.Insert(index, number);
    }
}